package com.ecube.mqtt.page.listener.chargelistener;

import com.ecube.mqtt.page.listener.pilechargelistener.PileChgStateListener;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ChgStatePageListener implements ActionListener {
    private JComboBox env;
    private JTextField gunid;
    private JTextField stationId;
    private JComboBox guncode1;


//    private JTextField vehicletext;
//    private JTextField vintext;
    private JFrame start;
    private  String path;
    public ChgStatePageListener(JFrame start,
                                JComboBox env,
                                JTextField stationId,
                                JTextField gunid,
                                JComboBox guncode,
                                String path) {
        this.start = start;
        this.env = env;
        this.stationId =stationId;
        this.gunid = gunid;
        this.guncode1 = guncode1;
        this.path = path;
//        this.vehicletext = vehicletext;
//        this.vintext = vintext;
    }

    public void actionPerformed(ActionEvent e) {
        start.dispose();

        Dimension dim2 = new Dimension(100, 30);
        Dimension dim3 = new Dimension(300, 30);
        Font font = new Font("宋体",Font.PLAIN,18);

        //生成新界面
        JFrame startpageres = new JFrame();
        startpageres.setSize(500, 700);
        startpageres.setTitle("充电枪状态");//设置窗体标题
        startpageres.setDefaultCloseOperation(2);
        startpageres.setLocationRelativeTo(null);
        startpageres.setFont(font);  //宋体，正常风格，14号字体
        //实例化FlowLayout流式布局类的对象，指定对齐方式为居中对齐组件之间的间隔为10个像素
        FlowLayout fl = new FlowLayout(FlowLayout.RIGHT,30,30);
        //实例化流式布局类的对象
        startpageres.setLayout(fl);

        JLabel labname = new JLabel("环境：");
        labname.setFont(font);
        //将labname标签添加到窗体上
        startpageres.add(labname);
        startpageres.add(env);


        JLabel stationname = new JLabel("枪ID：");
        stationname.setFont(font);
        //将labname标签添加到窗体上
        startpageres.add(stationname);
        startpageres.add(gunid);

        //实例化JLabel标签对象，该对象显示“A枪”
        JLabel code = new JLabel("枪编号：");
        code.setFont(font);
        //将labname标签添加到窗体上
        startpageres.add(code);

        JComboBox guncode = new JComboBox();
        guncode.setPreferredSize(dim3);//设置除顶级容器组件以外其他组件的大小
        guncode.setFont(font);
        guncode.addItem("A枪");
        guncode.addItem("B枪");
        guncode.addItem("AB枪");
        guncode.setSelectedItem("A枪");
        //env.getSelectedItem().toString()
        startpageres.add(guncode);

        //实例化JLabel标签对象，该对象显示“A枪”
        JLabel chgState = new JLabel("枪状态：");
        chgState.setFont(font);
        //将labname标签添加到窗体上
        startpageres.add(chgState);

        JComboBox state = new JComboBox();
        state.setPreferredSize(dim3);//设置除顶级容器组件以外其他组件的大小
        state.setFont(font);
        state.addItem("1-待机");
        state.addItem("2-充电中");
        state.addItem("3-充电完成");
        state.addItem("4-故障");
        state.addItem("5-离线");
        state.setSelectedItem("1-待机");
        //env.getSelectedItem().toString()
        startpageres.add(state);

        //实例化JLabel标签对象，该对象显示连接状态
        JLabel batConnS = new JLabel("连接状态：");
        batConnS.setFont(font);
        //将labname标签添加到窗体上
        startpageres.add(batConnS);

        JComboBox batConn = new JComboBox();
        batConn.setPreferredSize(dim3);//设置除顶级容器组件以外其他组件的大小
        batConn.setFont(font);
        batConn.addItem("1-已连接");
        batConn.addItem("2-未连接");
        batConn.setSelectedItem("1-已连接");
        //env.getSelectedItem().toString()
        startpageres.add(batConn);

        //实例化JButton组件
        JButton startResultButton = new JButton();
        //设置按键的显示内容
        startResultButton.setText("   点击发送   ");
        startResultButton.setFont(new Font("宋体",Font.PLAIN,18));
        //设置按键大小
        startResultButton.setSize(dim3);
        startpageres.add(startResultButton);

        ChgStateListener pileChgState = new ChgStateListener(startpageres,
                env,
                stationId,
                gunid,
                guncode,
                state,
                batConn,
                path);
        startResultButton.addActionListener(pileChgState);

        //实例化JButton组件
        JButton chargeReturnFirstPageButton = new JButton();
        //设置按键的显示内容
        chargeReturnFirstPageButton.setText("   返回首页   ");
        chargeReturnFirstPageButton.setFont(new Font("宋体",Font.PLAIN,18));
        //设置按键大小
        chargeReturnFirstPageButton.setSize(dim3);
        startpageres.add(chargeReturnFirstPageButton);


        BackListener chargeBack = new BackListener(startpageres, path);
        chargeReturnFirstPageButton.addActionListener(chargeBack);

        startpageres.setResizable(false);
        startpageres.setVisible(true);


    }
}